import requests
import re
import os
url = 'http://sc.chinaz.com/tupian/'
download = "picture/"
if(not os.path.exists(download)):
    os.mkdir(download)
response = requests.get(url)
# print(response.status_code) #获取响应的状态码，200表示成功
# print(response.text) #获取响应的网页内容(字符串，直接获取可能会有乱码问题)
print(response.content.decode('utf-8')) #获取网页的二进制内容,可以解决乱码问题
with open('picture.html','wb') as file:
    file.write(response.content)
imgPattern = r'<img src2="(.*?)" alt=".*"'
with open('picture.html','r',encoding='utf-8') as file:
    text = file.read()
result = re.findall(imgPattern,text)
print(result)
i = 0
for img in result:
    with open(download + "{}.jpg".format(i),"wb") as file:
        file.write(requests.get(img).content)
    print("第{}张图片下载完成".format(i))
    i += 1